<?php

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

if (!eregi("admin.php", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }
$sql = "SELECT radminsuper FROM ".$prefix."_authors WHERE aid='$aid'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if ($row[radminsuper] == 1) {

/*********************************************************/
/* Users Groups Functions                                      */
/*********************************************************/

function Groups() {
	global $bgcolor2, $bgcolor4, $prefix, $user_prefix, $db;
	include("header.php");
	GraphicAdmin();
	title(""._GROUPSADMIN."");
	$grp_num = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_groups"));
	if ($grp_num == 0) {
	    OpenTable();
	    echo "<center><font class=\"title\"><b>"._NOGROUPS."</b></font></center>";
	    CloseTable();
	    echo "<br>";
	} else {
	    OpenTable();
	    echo "<center><font class=\"title\"><b>"._UGROUPS."</b></font></center>"
		."<br><table border=\"1\" width=\"100%\"><tr>"
		."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._NAME."</b></td>"
		."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._DESCRIPTION."</b></td>"
		."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._POINTS."</b></td>"
		."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._USERSCOUNT."</b></td>"
		."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></td></tr>";
	    $sql = "SELECT id, name, description, points FROM ".$prefix."_groups ORDER BY points";
	    $result = $db->sql_query($sql);
	    while ($row = $db->sql_fetchrow($result)) {
		$id = $row[id];
		$users_num = $db->sql_numrows($db->sql_query("SELECT * FROM ".$user_prefix."_users WHERE points>='$row[points]'"));
		echo "<tr>"
		    ."<td align=\"left\" nowrap>&nbsp;$row[name]&nbsp;</td>"
		    ."<td align=\"left\">$row[description]</td>"
		    ."<td align=\"center\">$row[points]</td>"
		    ."<td align=\"center\">$users_num</td>"
		    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;[ <a href=\"admin.php?op=grp_edit&amp;id=$row[id]\">"._EDIT."</a> | <a href=\"admin.php?op=grp_del&amp;id=$row[id]\">"._DELETE."</a> ]&nbsp;</font></td></tr>";
	    }
	    echo "</table>";
	    CloseTable();
	    echo "<br>";
	}
	OpenTable();
	echo "<center><font class=\"option\"><b>"._ADDNEWGROUP."</b></font></center><br><br>"
	    ."<form action=\"admin.php\" method=\"post\">"
	    ."<table border=\"0\" width=\"100%\">"
	    ."<tr><td>"._GTITLE.":</td><td><input type=\"text\" name=\"name\" size=\"50\" maxlength=\"255\"></td></tr>"
	    ."<tr><td>"._DESCRIPTION.":</td><td><textarea name=\"description\" cols=\"50\" rows=\"10\"></textarea></td></tr>"
	    ."<tr><td>"._POINTSNEEDED.":</td><td><input type=\"text\" name=\"points\" size=\"10\" maxlength=\"20\" value=\"0\">&nbsp;<i>("._ONLYNUMVAL.")</i></td></tr>"
	    ."</table><br><br>"
	    ."<input type=\"hidden\" name=\"op\" value=\"grp_add\">"
	    ."<input type=\"submit\" value=\""._CREATEGROUP."\"></form>";
	CloseTable();
	echo "<br>";
	OpenTable();
	echo "<center><font class=\"option\"><b>"._POINTSSYSTEM."</b></font></center><br><br>"
	    ."<table border=\"1\" width=\"100%\"><tr>"
	    ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._NAME."</b></td>"
	    ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._DESCRIPTION."</b></td>"
	    ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._POINTS."</b></td>"
	    ."<td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='1'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS01."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC01."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"1\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='2'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS02."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC02."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"2\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='3'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS03."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC03."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"3\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='4'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS04."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC04."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"4\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='5'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS05."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC05."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"5\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='6'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS06."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC06."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"6\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='7'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS07."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC07."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"7\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='8'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS08."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC08."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"8\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='9'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS09."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC09."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"9\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='10'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS10."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC10."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"10\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='11'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS11."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC11."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"11\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='12'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS12."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC12."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"12\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='13'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS13."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC13."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"13\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='14'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS14."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC14."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"14\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='15'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS15."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC15."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"15\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='16'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS16."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC16."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"16\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='17'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS17."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC17."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"17\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='18'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS18."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC18."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"18\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='19'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS19."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC19."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"19\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='20'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS20."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC20."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"20\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>"
	    ."<tr>";
	$row = $db->sql_fetchrow($db->sql_query("SELECT points FROM ".$prefix."_groups_points WHERE id='21'"));
	echo "<form action=\"admin.php\" method=\"post\">"
	    ."<td align=\"left\" nowrap>&nbsp;"._POINTS21."&nbsp;</td>"
	    ."<td align=\"left\">"._DESC21."</td>"
	    ."<td align=\"center\">&nbsp;<input type=\"text\" value=\"$row[points]\" size=\"5\" name=\"points\">&nbsp;</td>"
	    ."<td align=\"center\" nowrap><font class=\"content\">&nbsp;"
	    ."<input type=\"hidden\" name=\"id\" value=\"21\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"points_update\">"
	    ."<input type=\"submit\" value=\""._UPDATE."\"></form>&nbsp;</font></td></tr>";
	echo "</table>";
	CloseTable();
	include("footer.php");
}

function grp_add($name, $description, $points) {
    global $prefix, $db;
    if (!is_numeric($points) || ereg("-", $points)) {
	include("header.php");
	GraphicAdmin();
	title(""._GROUPSADMIN."");
	OpenTable();
	echo "<center><b>"._GROUPADDERROR."</b><br><br>"
	    .""._NONUMVALUE."<br><br>"
	    .""._GOBACK."</center>";
	CloseTable();
	include("footer.php");
    } else {
	$db->sql_query("INSERT INTO ".$prefix."_groups VALUES (NULL, '$name', '$description', '$points')");
	Header("Location: admin.php?op=Groups");
    }
}

function grp_edit($id) {
    global $prefix, $db;
    include("header.php");
    GraphicAdmin();
    title(""._GROUPSADMIN."");
    $sql = "SELECT * FROM ".$prefix."_groups WHERE id='$id'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    OpenTable();
    echo "<center><font class=\"option\"><b>"._EDITGROUP."</b></font></center><br><br>"
        ."<form action=\"admin.php\" method=\"post\">"
        ."<table border=\"0\" width=\"100%\">"
        ."<tr><td>"._GTITLE.":</td><td><input type=\"text\" name=\"name\" size=\"50\" maxlength=\"255\" value=\"$row[name]\"></td></tr>"
        ."<tr><td>"._DESCRIPTION.":</td><td><textarea name=\"description\" cols=\"50\" rows=\"10\">$row[description]</textarea></td></tr>"
        ."<tr><td>"._POINTSNEEDED.":</td><td><input type=\"text\" name=\"points\" size=\"10\" maxlength=\"20\" value=\"$row[points]\">&nbsp;<i>("._ONLYNUMVAL.")</i></td></tr>"
        ."</table><br><br>"
	    ."<input type=\"hidden\" name=\"id\" value=\"$id\">"
        ."<input type=\"hidden\" name=\"op\" value=\"grp_edit_save\">"
        ."<input type=\"submit\" value=\""._SAVEGROUP."\"></form>";
    CloseTable();
    include("footer.php");
}

function grp_edit_save($id, $name, $description, $points) {
    global $prefix, $db;
    if (!is_numeric($points)) {
	include("header.php");
	GraphicAdmin();
	title(""._GROUPSADMIN."");
	OpenTable();
	echo "<center><b>"._GROUPADDERROR."</b><br><br>"
	    .""._NONUMVALUE."<br><br>"
	    .""._GOBACK."</center>";
	CloseTable();
	include("footer.php");
    } else {
	$db->sql_query("UPDATE ".$prefix."_groups SET name='$name', description='$description', points='$points' WHERE id='$id'");
	Header("Location: admin.php?op=Groups");
    }
}

function grp_del($id, $ok=0) {
    global $prefix, $db;
    if ($ok == 0) {
	include("header.php");
	GraphicAdmin();
	title(""._GROUPSADMIN."");
	OpenTable();
	$sql = "SELECT name FROM ".$prefix."_groups WHERE id='$id'";
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	echo "<center><b>"._GROUPDELETE."</b><br><br>"
	    .""._SUREGRPDEL1." <b>$row[name]</b><br><br>"
	    ."[ <a href=\"admin.php?op=grp_del&id=$id&ok=1\">"._YES."</a> | <a href=\"admin.php?op=Groups\">"._NO."</a> ]</center>";
	CloseTable();
	include("footer.php");
    } else {
	$db->sql_query("DELETE FROM ".$prefix."_groups WHERE id='$id'");
	$db->sql_query("UPDATE ".$prefix."_modules SET mod_group='0' WHERE mod_group='$id'");
	Header("Location: admin.php?op=Groups");
    }
}

function p_update($points, $id) {
    global $prefix, $db;
    $db->sql_query("UPDATE ".$prefix."_groups_points SET points='$points' WHERE id='$id'");
    Header("Location: admin.php?op=Groups");
}

switch($op) {

    case "Groups":
    Groups();
    break;

    case "grp_add":
    grp_add($name, $description, $points);
    break;

    case "grp_edit":
    grp_edit($id);
    break;
    
    case "grp_edit_save":
    grp_edit_save($id, $name, $description, $points);
    break;

    case "grp_del":
    grp_del($id, $ok);
    break;

    case "points_update":
    p_update($points, $id);
    break;

}

} else {
    echo "Access Denied";
}

?>
